<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="button1">点击按钮 1</button>
<button id="button2">点击按钮 2</button>
<button id="button3">点击按钮 3</button>
<script>
    var button1 = document.getElementById('button1'),
        button2 = document.getElementById('button2'),
        button3 = document.getElementById('button3');
    var setCommand = function( button, func ){
        button.onclick = function(){
            func();
        }
    };
    var MenuBar = {
        refresh: function(){
            console.log( '刷新菜单界面' );
        }
    };
   /* var RefreshMenuBarCommand = function( receiver ){
        return function(){
            receiver.refresh();
        }
    };
    var refreshMenuBarCommand = RefreshMenuBarCommand( MenuBar );
    setCommand( button1, refreshMenuBarCommand );*/
    var RefreshMenuBarCommand = function( receiver ){
        return {
            execute: function(){
                receiver.refresh();
            }
        }
    };
    var setCommand = function( button, command ){
        button.onclick = function(){
            command.execute();
        }
    };
    var refreshMenuBarCommand = RefreshMenuBarCommand( MenuBar );
    setCommand( button1, refreshMenuBarCommand );
</script>

</body>
</html>